<?
include "server_config.php";
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> 넥도닥 [NextDoorDoctor] :: 데이터베이스 </title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style>
a:link {text-decoration:none} 
a:visited {text-decoration:none} 
a:active {text-decoration:none} 
a:hover {color:blue;text-decoration:none} 
</style>

 </head>

 <body style="line-height: 160%; font-size: 12px; font-family: '굴림'; padding: 0px; margin: 0px;  ">
  <table border=0 width='1000px' align='center'>
	
<?
include "nddg_top_menu.php";
?>	

	<tr>
		<td>
			<div style='width:300px;float:left;'>
				자주 묻는 FAQ<br><br>
				질문 1<br>
				질문 2<br>
				질문 3<br>
				질문 4<br>
				질문 5<br>
				<br><br><br>
				갑상선 암이란?<br><br>
				1.	갑상선의 기능<br>
				2.	갑상선 암의 종류<br>
				3.	갑상선 암의 치료 과정<br>
				
			</div>
			<div style='width:700px;float:left;'>
				<div  style='width:300px;float:left; text-align:center;'>
					<?
						$sql="
							SELECT id, name, count FROM nddg_question_category WHERE id<5 ORDER BY id ;
						";

						$result = mysql_query($sql,$connect);

						while($row = mysql_fetch_row($result))
						{
					?>
							<a href='nddg_db_category.php?category=<?=$row[0]?>'><b>[ <?=$row[1]?> ]</b></a><br>

							<?
								$sql_sub="
									SELECT id, content, view_count, answer_count FROM nddg_question WHERE category_id=".$row[0]." ORDER BY view_count DESC LIMIT 5 ;
								";

								$result_sub = mysql_query($sql_sub,$connect);

								while($row_sub = mysql_fetch_row($result_sub))
								{

							?>
								<a href='nddg_db_category.php?question=<?=$row_sub[0]?>'><?=$row_sub[1]?></a><br>
							<?
								}
							?>

							<br>

					<?
						}
					?>
				</div>
				<div  style='width:100px;height:300px;float:left; text-align:center;'>
					<br>
					<br>
					<br>
					<br>
					<br>
					<br>
					갑상선암!<br>
					무엇을 알아야<br>
					할까요?
				</div>
				<div  style='width:300px;float:left; text-align:center;'>
					<?
						$sql="
							SELECT id, name, count FROM nddg_question_category WHERE id>=5 ORDER BY id ;
						";

						$result = mysql_query($sql,$connect);

						while($row = mysql_fetch_row($result))
						{
					?>
							<a href='nddg_db_category.php?category=<?=$row[0]?>'><b>[ <?=$row[1]?> ]</b></a><br>

							<?
								$sql_sub="
									SELECT id, content, view_count, answer_count FROM nddg_question WHERE category_id=".$row[0]." ORDER BY view_count DESC LIMIT 5 ;
								";

								$result_sub = mysql_query($sql_sub,$connect);

								while($row_sub = mysql_fetch_row($result_sub))
								{

							?>
								<a href='nddg_db_category.php?question=<?=$row_sub[0]?>'><?=$row_sub[1]?></a><br>
							<?
								}
							?>

							<br>

					<?
						}
					?>
				</div>
				

				<div style='width:700px;height:30px;float:left;'>
				</div>
				<div style='width:700px;height:20px;float:left;background:#eee;'>
				</div>
				<div style='width:700px;float:left; text-align:center;background:#eee;' id='search_box'>
					무엇이 궁금하세요? <input type='text' name='input_question'> <input type='button' value='검색'><br>
					<br>
					떠오르는 단어를 입력하시면 관련 질문들이 아래에 제공됩니다.<br>
				</div>
				<div style='width:660px;padding:20px;float:left;background:#eee;' id='search_result'>
					<?
						$sql_sub="
							SELECT id, content, view_count, answer_count FROM nddg_question ORDER BY view_count DESC LIMIT 5 ;
						";

						$result_sub = mysql_query($sql_sub,$connect);

						while($row_sub = mysql_fetch_row($result_sub))
						{

					?>
					<hr>
						
						<b><?=$row_sub[1]?></b><br>

							<?
								$sql_answer="
									SELECT id, content, user_id FROM nddg_answer WHERE question_id=".$row_sub[0]."  LIMIT 1 ;
								";

								$result_answer = mysql_query($sql_answer,$connect);

								$row_answer = mysql_fetch_row($result_answer);

								echo utf8_strcut($row_answer[1],200);							

							?>
							<br>
							<a href='nddg_db_category.php?question=<?=$row_sub[0]?>'>
								- 전체보기 (3개의 답이 더 있습니다.)
							</a>
						
						<br>
					<?
						}
					?>
					<br>

				</div>


			</div>



			
		</td>
	</tr>
	<tr>
		<td height='10px'>
		
		</td>
	</tr>
	<tr>
		<td height='1px'>
			<div style='background:#ccc;width:1000px;height:1px;'><span></span></div>
		</td>
	</tr>
	<tr>
		<td>
			<div style='width:230px;height:50px;padding:10px; float:right; text-align:right;'>
					© 2011 Next Door Doctor
			</div>
		</td>
	</tr>
  </table>
 </body>
</html>

<?
function utf8_strcut( $str, $size )
{
        $substr = substr( $str, 0, $size * 2 );
        $multi_size = preg_match_all( '/[\\x80-\\xff]/', $substr, $multi_chars );

        if ( $multi_size > 0 )
            $size = $size + intval( $multi_size / 3 ) - 1;

        if ( strlen( $str ) > $size )
        {
            $str = substr( $str, 0, $size );
            $str = preg_replace( '/(([\\x80-\\xff]{3})*?)([\\x80-\\xff]{0,2})$/', '$1', $str );
            $str .= '...';
        }

        return $str;
}
?>